﻿using System.Collections.Generic;
using System;

namespace MyHealthByDesign.Domain.Processing
{
    /// <summary>
    /// Description:
    /// Range class provides processing logic for range processing type.
    /// 
    /// Author: Mark Servais
    /// Date Created: 11/19/2011
    /// 
    /// Other code files referenced:
    /// IProcessing.cs
    /// 
    /// Regression Test Information:
    /// Range_Test.cs in project MyHealthByDesign_Test
    /// 
    /// Revision History:
    /// None.
    /// 
    /// Known Faults:
    /// None.
    /// </summary>
    public class Range : IProcessing
    {
        #region IProcessing Members

        /// <summary>
        /// RunProcessingForField - Executes the processing logic
        /// web page
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// boolean value is returned based on success of logic
        /// </summary>
        /// <param name="question"></param>
        /// <returns></returns>
        public bool RunProcessingForField(Question question, QuestionProcessing process)
        {
            bool bValid = false;
            int nStep = 0;

            List<string> listValues = new List<string>(process.QuestionProcessingValues.Split('|'));

            if(listValues.Count == 3)
                bValid = Int32.TryParse(listValues[2], out nStep);

            int i = Convert.ToInt32(listValues[0]);

            while ( i <= Convert.ToInt32(listValues[1]) )
            {
                question.FieldOptions.Add(new QuestionOption { Id = 0, Name = i.ToString(), OptionLabel = i.ToString(), SortOrder = i, FieldName = process.FieldName});

                if (bValid)
                    i += nStep;
                else
                    i++;
            }

            return true;


        }

        #endregion
    }
}